package com.gui.windows.components;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.util.List;
import java.util.ArrayList;
import com.gui.windows.Sizes;
import com.gui.*;

/**
 * Singleton Class that manage the state panel used to debrief components data to the user.
 * */

public class StatePanel extends JPanel implements GuiComponents {

	//**************************************************************************************************
	//	Constructor.
	//**************************************************************************************************
	
	static private StatePanel statePanel = null;
	
	private StatePanel(String name) {
		super();
		createPanel(name);
	}
	
	static public StatePanel getStatePanel(String name ) {
		if (statePanel == null) {
			statePanel = new StatePanel(name);
		} 
		return statePanel;
	}
	
	//**************************************************************************************************
	//	Atributes.
	//**************************************************************************************************

	private List <JLabel> atributes;
	private List <JLabel> values;
	
	private static boolean enabled = false;
		
	//**************************************************************************************************
	//	Methods that exports this Class (Public Methods).
	//**************************************************************************************************
	
	public void setMessages(List <String> atribs, List <String> values) {
		JLabel auxLabel;
		for (int i = 0 ; i < atribs.size() ; ++i) { // can exist atribs without value, but nos values without atrib.
			auxLabel = new JLabel();
			auxLabel.setText(atribs.get(i));
			this.atributes.add(auxLabel);
			auxLabel = new JLabel();
			auxLabel.setText(values.get(i));
			this.values.add(auxLabel);
		}
		showMessages();
	}
	
	public void setEnabled (boolean enabled) {}
	
	public void update() {}
	
	//**************************************************************************************************
	//	Inner Methods. (Private Methods).
	//**************************************************************************************************
	
	private void createPanel(String name) {
		this.setName(name);
		initComponents();
	}
	
	private void initComponents() {
		atributes = new ArrayList <JLabel> ();
		values= new ArrayList <JLabel> ();
	}
		
	private void showMessages () {
		this.removeAll();
		for (int i = 0 ; i < atributes.size() ; ++i) {
			this.add(atributes.get(i));
			this.add(values.get(i));
		}
		setComponentsPosition();
	}
	
	private void setComponentsPosition() {
		int startY = 20;
		int atribX = 20;
		int valueX = 60;
		int yOffset = 0;
		this.setLayout(null);
		for (int i = 0 ; i < atributes.size() ; ++i) { 
			atributes.get(i).setBounds(atribX, startY + yOffset, Sizes.LABEL_WIDTH, Sizes.LABEL_HEIGHT);
			values.get(i).setBounds(valueX, startY + yOffset, Sizes.LABEL_WIDTH, Sizes.LABEL_HEIGHT);
			yOffset += Sizes.LABEL_HEIGHT;
		}
	}
	
	//**************************************************************************************************
	//	Inner Classes.
	//**************************************************************************************************
}
